package com.soft.bams.entity;

import com.soft.bams.exception.BalanceNotEnoughException;

import java.io.Serializable;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/4/18
 */
//要求1：完成以下两种账户类型的编码。
//银行的客户分为两大类：储蓄账户(SavingAccount)和信用账户(CreditAccount),
// 两种的账户类型的区别在于：
//储蓄账户不允许透支,而信用账户可以透支,并在用户在满足银行条件的情况下允许用户
// 调整自己的透支额度.
//        注意:
//        1、CreditAccount需要多一个属性 ceiling 透支额度；
//        2、CreditAccount需要覆盖（重写）Account中的取款方式withdraw()。

public class CreditAccount extends Account implements Serializable {
    private static final long serialVersionUID = -5368782898548865631L;
    private double ceiling;//透支额度
    public double getCeiling() {
        return ceiling;
    }
    public void setCeiling(double ceiling) {
        this.ceiling = ceiling;
    }
    public CreditAccount(Long id, String password, String name,
                         String personid, String email, double balance,double ceiling) {
        super(id, password, name, personid, email, balance);
        this.ceiling = ceiling;
    }
    public String toString() {
        return "CreditAccount{" + "ceiling=" + ceiling + "} " + super.toString();
    }
    @Override
    public Account withdraw(double money)throws BalanceNotEnoughException {
        if(money>getBalance()+this.ceiling){
//            System.out.println("您的余额不足！");
//            return this;
            throw new BalanceNotEnoughException("您的余额不足!");
        }else if(money>getBalance()){
            this.ceiling=this.ceiling-(money-getBalance());
            setBalance(0);
            return this;
        }
            setBalance(getBalance()-money);
            return this;
    }
}


